package com.hgy.crowd.service.impl;

import com.hgy.crowd.mapper.MemberPOMapper;
import com.hgy.crowd.po.MemberPO;
import com.hgy.crowd.po.MemberPOExample;
import com.hgy.crowd.service.MemberService;
import com.hgy.crowd.util.ResultEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author He
 * @Date 2020/6/30 11:11
 */
@Transactional(readOnly = true)
@Service
public class MemberServiceImpl implements MemberService {
    @Resource
    private MemberPOMapper memberPOMapper;
    @Override
    public ResultEntity getMemberByLoginAccount(String account) {
        MemberPOExample memberPOExample = new MemberPOExample();
        MemberPOExample.Criteria criteria = memberPOExample.createCriteria();
        criteria.andLoginacctEqualTo(account);
        List<MemberPO> memberPOS = memberPOMapper.selectByExample(memberPOExample);
        if (memberPOS.size()==0){
            return ResultEntity.failed("没有此用户信息");
        }
        return ResultEntity.successWithData(memberPOS.get(0));
    }
    @Transactional(propagation = Propagation.REQUIRES_NEW,
                    rollbackFor = Exception.class)
    @Override
    public void saveMember(MemberPO memberPO) {
        memberPOMapper.insertSelective(memberPO);
    }
}
